#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<unistd.h>

char* const addenv[] = {
    (char* const)"MYVAL=123456789",
    NULL
};

int main()
{
    printf("我的程序要运行了！\n");

    if(fork() == 0)
    {
        // child
        printf("I am Child, My Pid Is: %d\n", getpid());
        sleep(1);

        char* const argv[] = {
            (char* const)"other",
            (char* const)"-a",
            (char* const)"-b",
            (char* const)"-c",
            (char* const)"-d",
            NULL 
        };
        
        for(int i = 0; addenv[i]; i++)
        {
            putenv(addenv[i]);
        }
        extern char** environ;
        execvpe("./other", argv, environ);

        //execvpe("./other", argv, env);

        // execvp(argv[0], argv);

        //execv("/usr/bin/ls", argv);
        //execlp("ls", "ls", "ln", "-a", NULL);
        //execl("/usr/bin/ls", "usr/bin/ls", "-ln", "-a", NULL);
        //execl("./other", "other", NULL);
        exit(1);
    }

    waitpid(-1, NULL, 0);
    printf("我的程序运行完毕了\n");
    
   // return 0;
}
